import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:xvideos/hj_utils/api_service/mine_service.dart';
import 'package:xvideos/tools_base/global_store/store.dart';

import '../../../../../hj_utils/utils.dart';
import '../../../hj_model/user/user_info_model.dart';

class MineIdentityLogic extends GetxController {
  MineIdentityLogic get to => Get.find<MineIdentityLogic>();

  UserInfoModel? meInfo = globalStore.getMe();

  // WalletModelEntity? get wallet => globalStore.getWallet();

  GlobalKey boundaryKey = GlobalKey();
  String qrCodeStr = '';

  int? inviterNum;

  @override
  void onReady() {
    super.onReady();
    loadData();
  }

  void loadData() async {
    globalStore.updateUserInfo();
    qrCodeStr = await MineService.certificateQR() ?? '';
    update();
  }

  ///保存图片
  Future<void> saveImage(BuildContext context) async {
    RenderRepaintBoundary? boundary = boundaryKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;
    var image = await boundary?.toImage(pixelRatio: 3.0);
    ByteData? byteData = await image?.toByteData(format: ImageByteFormat.png);
    bool suc = await savePngDataToAblumn(byteData?.buffer.asUint8List());
  }
}
